Ext.define('ContractManage', {
    extend: 'Ext.data.Model',
    fields: [
        "Id"
        , "Name"//合同名称
        , "Code"//合同编号
		, "CompanyName"   //甲方名称
		, "CompanyID"   //甲方ID
		, "HroName"   //乙方名称
		, "HroID"   //乙方ID
		, "SignDateTime"   //签订日期
		, "StartDateTime"   //合同起始日期
		, "EndDateTime"   //合同截止日期
		, "EffectiveDate"   //合同有效期
		, "ConstractType"   //合同类型
		, "ConstractState"   //合同状态
		, "ConstractScale"   //合同规模
		, "AdjunctName"   //合同附件
		, "AdjunctID"   //合同附件ID
		, "Remarks"   //备注
				    ],
    idProperty: "Id"
});

Ext.define('SHApp.ClientInfo.BagManage.Grid', {
    extend: 'BLBTSystem.grid',
    alias: 'widget.clientinfogrid',
    //requires: ['SHApp.ClientInfo.ContractManage.Form'],
    txtCompanyNameID: 'txtCompanyName',
    txtSignDateTimeID: 'txtSignDateTime',
    dataModel: "ContractManage",
    dataUrl: "api/contractmanage?format=json",
    singleSelect: true,
    initComponent: function () {
        var me = this;
        Ext.apply(this);
        me.btnAddID += me.id;
        me.btnEditID += me.id;
        me.btnDeleteID += me.id;
        me.txtCompanyNameID += me.id;
        me.txtSignDateTimeID += me.id;
        this.creatTbar();
        this.creatColumns();
        this.callParent(arguments);
        this.checkBtnPermission(me.pvalue);
    },
    creatColumns: function () {
        var me = this;
        me.columns = [{
            text: "Id",
            flex: 1,
            dataIndex: 'Id',
            sortable: false,
            hidden: true
        }, {
            text: "合体编号",
            width: 120,
            dataIndex: 'Code',
            sortable: true
        }, {
            text: "合体名称",
            width: 120,
            dataIndex: 'Name',
            sortable: true
        }, {
            text: "甲方名称",
            width: 120,
            dataIndex: 'CompanyName',
            sortable: true
        }, {
            text: "甲方ID",
            width: 100,
            dataIndex: 'CompanyID',
            sortable: true,
            hidden: true
        }, {
            text: "合同起始日期",
            width: 120,
            dataIndex: 'StartDateTime',
            sortable: true,
            renderer: formatDate
        }, {
            text: "合同截止日期",
            width: 120,
            dataIndex: 'EndDateTime',
            sortable: true,
            renderer: formatDate
        }
		];
    },
    creatTbar: function () {
        var me = this;
        me.tbar = [
		    {
		        xtype: 'textfield',
		        disabled: false,
		        fieldLabel: '甲方名称:',
		        labelWidth: 60,
		        name: 'CompanyName',
		        id: me.txtCompanyNameID,
		        width: 150
		    },
				{
				    xtype: 'datefield',
				    disabled: false,
				    fieldLabel: '签订日期:',
				    labelWidth: 60,
				    name: 'SignDateTime',
				    id: me.txtSignDateTimeID,
				    value: new Date(),
				    format: "Y-m-d",
				    width: 180
				},
			{
			    xtype: 'button',
			    text: '查询',
			    iconCls: 'icon-btn-search',
			    handler: function () {
			        me.clearFilters();
			        var vCompanyName = me.down("#" + me.txtCompanyNameID).getValue();
			        if (vCompanyName && vCompanyName.length > 0) {
			            me.addFilter("CompanyName", vCompanyName);
			        }

			        var vSignDateTime = getDateString(me.down("#" + me.txtSignDateTimeID).getValue());
			        if (vSignDateTime && vSignDateTime.length > 0) {
			            me.addFilter("SignDateTime", vSignDateTime);
			        }

			        me.loadByFilter();
			    }
			}
        ]
    }
})

